package cn.jiyun.service.impl;

import cn.jiyun.dao.UserDao;
import cn.jiyun.pojo.User;
import cn.jiyun.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public User findById(Long id) {
        return userDao.selectById(id);
    }

    @Override
    public Page<User> findPage(Integer pageIndex,String name) {
        Page<User> page = new Page<>(pageIndex,2);
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(name!=null,User::getUsername,name);
        return userDao.selectPage(page,queryWrapper);
    }

    @Override
    public void del(Integer id) {
        userDao.deleteById(id);
    }

    @Override
    public User findId(Integer id) {
        return userDao.selectById(id);
    }

    @Override
    public void add(User user) {
        userDao.insert(user);
    }

    @Override
    public void edit(User user) {
        userDao.updateById(user);
    }
}
